﻿/*
 * Cratos Desktop
 * Cratos Cache Data Object Element Collection class
 * 
 * Copyright (c) 2011 Draco
 * 
 * This file is part of Cratos.
 * 
 * Cratos is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Cratos is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Cratos.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *       .==.        .==.
 *      //'^\\      //^'\\
 *     // ^ ^\(\__/)/^ ^^\\
 *    //^ ^^ ^/6  6\ ^^ ^ \\
 *   //^ ^^ ^/( .. )\^ ^ ^ \\
 *  // ^^ ^/\| V""V|/\^ ^ ^ \\
 * //^^/\/ /  '~~'  \ \/\^ ^ \\
 *  ------------------------------------
 *  HERE BE DRAGONS
 *  
 *  Johan Dercksen - johan@draco.co.za
 */
using System;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Generic;

namespace Cratos.Desktop
{
	/// <summary>
	/// Cache Data Object Element Collection class
	/// </summary>
	public class CacheDataObjectElementCollection : ConfigurationElementCollection
	{
		#region Class Constant declarations
		#endregion

		#region Class Event declarations
		#endregion

		#region Class Variable declarations
		#endregion

		#region Class Constructors & Destructors
		/// <summary>
		/// Class Constructor
		/// </summary>
		public CacheDataObjectElementCollection() { }
		#endregion

		#region Class Properties
		/// <summary>
		/// Collection Type
		/// </summary>
		public override ConfigurationElementCollectionType CollectionType
		{
			get { return (ConfigurationElementCollectionType.BasicMap); }
		}

		/// <summary>
		/// Element Name
		/// </summary>
		protected override string ElementName
		{
			get { return("CacheDataObject");  }
		}

		/// <summary>
		/// Element
		/// </summary>
		/// <param name="serviceName">Cache Data Object Element Name</param>
		/// <returns>
		/// Cache Data Object Element corresponding to the input value
		/// </returns>
		new public CacheDataObjectElement this[string serviceName]
		{
			get { return ((CacheDataObjectElement)this.BaseGet(serviceName)); }
		}

		/// <summary>
		/// Element
		/// </summary>
		/// <param name="elementIndex">Add In Element index</param>
		/// <returns>
		/// Add In Element corresponding to the input value
		/// </returns>
		public CacheDataObjectElement this[int elementIndex]
		{
			get { return ((CacheDataObjectElement)this.BaseGet(elementIndex)); }
			set
			{
				// Remove the element if required
				if (this.BaseGet(elementIndex) != null) { this.BaseRemoveAt(elementIndex); }

				// Add the element to the collection
				this.BaseAdd(elementIndex, value);
			}
		}
		#endregion

		#region Class Methods
		/// <summary>
		/// Create a new element
		/// </summary>
		/// <returns></returns>
		protected override ConfigurationElement CreateNewElement()
		{
			// Create the new element required
			return (new CacheDataObjectElement());
		}

		/// <summary>
		/// Retrieve the specified elements key
		/// </summary>
		/// <param name="serviceElement">Service Element</param>
		/// <returns>
		/// Key of the specified element
		/// </returns>
		protected override Object GetElementKey(ConfigurationElement serviceElement)
		{
			// Retrieve the specified elements name
			return (((CacheDataObjectElement)serviceElement).Name);
		}

		/// <summary>
		/// Add a new element to the collection
		/// </summary>
		/// <param name="serviceElement">Service Element</param>
		public void Add(CacheDataObjectElement serviceElement)
		{
			// Add the element to the collection
			this.BaseAdd(serviceElement);
		}
		#endregion

		#region Class Support Methods
		#endregion
	}
}
